var slideIndex = 1;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("dot");

setTimeout(() => {
    while (slides.length && dots.length) {
        showSlides(slideIndex);
        break;
    }
}, 1000)

// 上一页 下一页
function plusSlides(n) {
    showSlides(slideIndex += n);
}

// 指定跳转到哪一图片
function currentSlide(n) {
    showSlides(slideIndex = n);
}

function showSlides(n) {
    if (n > slides.length) {slideIndex = 1} 
    if (n < 1) {slideIndex = slides.length}
    for (var i = 0; i < slides.length; i++) {
        slides[i].style.display = "none"; 
    }
    for (i = 0; i < dots.length; i++) {
        dots[i].className = dots[i].className.replace(" active", "");
    }
    // console.log(slideIndex)
    slides[slideIndex-1].style.display = "block"; 
    dots[slideIndex-1].className += " active";
  }